﻿using MaterialSkin;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Materialize
{
    class FormStyle
    {
        private readonly List<Primary> Primary;
        private readonly List<Accent> Accent;
        private int header,body,acc,text;

        private MaterialSkinManager skinManager;

        /// <summary>
        /// 头部颜色
        /// </summary>
        public int Header { get => header; set => SetStyle(value, Body, Acc, Text); }
        /// <summary>
        /// 主体颜色
        /// </summary>
        public int Body { get => body; set => SetStyle(Header, value, Acc, Text); }
        /// <summary>
        /// 控件颜色
        /// </summary>
        public int Acc { get => acc; set => SetStyle(Header, Body, value, Text); }
        /// <summary>
        /// 字体颜色
        /// </summary>
        public int Text { get => text; set => SetStyle(Header, Body, Acc, value); }

        public FormStyle(MaterialSkinManager skinManager)
        {
            Primary = new List<Primary>();
            Accent = new List<Accent>();
            foreach (int color in Enum.GetValues(typeof(Primary)))
            {
                Primary.Add((Primary)(color));
            }
            foreach (int color in Enum.GetValues(typeof(Accent)))
            {
                Accent.Add((Accent)(color));
            }
            this.skinManager = skinManager;
            SetStyle(9, 8, 13, 1);
        }
        
        public void ChangeText()
        {
            Text = Text == 0 ? 1 : 0;
            SetStyle(Header, Body, Acc, Text);
        }

        public void SetStyle(int header, int body, int acc,int text)
        {
            this.header = Math.Max(0, header);this.body = Math.Max(0,body);this.acc = Math.Max(0, acc);this.text = text;
            this.skinManager.ColorScheme = new ColorScheme(Primary[this.body], Primary[this.header], Primary[this.body], Accent[this.acc], text == 0 ? TextShade.BLACK:TextShade.WHITE);
        }

        public List<Primary> GetPrimary()
        {
            return this.Primary;
        }

        public List<Accent> GetAccent()
        {
            return this.Accent;
        }
    }
}
